import * as echarts from '../../components/ec-canvas/echarts';
 
 
const app = getApp();
 
 
function initChart(canvas, width, height, dpr) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr // new
  });
  canvas.setChart(chart);
 
 
  var option = {
    // tooltip: {
    //   show: true,
    //   formatter: "{a}\n{b} : {c} ({d}%)"
    // },
    //calculable: true,
    title: {
      text: '数据统计',
      left: 'center'
    },
    backgroundColor: "#ffffff",
    color: ["#37A2DA", "#32C5E9", "#67E0E3", "#91F2DE", "#FFDB5C", "#FF9F7F"],
    legend: {
      orient : 'vertical',
      x : 'right',
      data:['食品','约会','生日','工作','上课'],
    },
    series: [{
      label: {
        normal: {
          fontSize: 14
        }
      },
      type: 'pie',
      center: ['50%', '50%'],
      radius: '60%',//['40%', '60%'],
      itemStyle: {
        normal: {
          label: {
            show: true,
            //position: 'inner',
            formatter: function(params) {
              return (params.percent - 0).toFixed(0) + '%'
            }
          },
          labelLine: {
            show: false
          }
        },
        emphasis: {
          label: {
            show: true,
            formatter: "{b}\n{d}%"
          }
        }
      },
      data: [{
        value: 55,
        name: '食品'
      }, {
        value: 20,
        name: '约会'
      }, {
        value: 1,
        name: '生日'
      }, {
        value: 20,
        name: '工作'
      }, {
        value: 38,
        name: '上课'
      }]
    }]
  };
 
 
  chart.setOption(option);
  return chart;
}
 
 
Page({
 
 
  /**
   * 页面的初始数据
   */
  data: {
    ec: {
      onInit: initChart
    },
    list:[
      {'id':1,"categories":"食品","count":"41%"},
      {'id':2,"categories":"食品","count":"41%"},
      {'id':3,"categories":"食品","count":"41%"},
    ]
  },
 
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
 
 
  },
})